#if TMP_PRESENT
using UnityEditor;
using UnityEngine;

namespace UnityDefaultSetting.TextMeshProDefaultSetting.Editor
{
    [UnityEditor.CustomEditor(typeof(TextMeshProDefaultSettingConfig))]
    public class TextMeshProDefaultSettingConfigEditor : UnityEditor.Editor
    {
        protected SerializedProperty defaultDeltaSizeProp;
        protected SerializedProperty defaultFontProp;
        protected SerializedProperty defaultFontSizeProp;
        protected SerializedProperty defaultFontColorProp;
        protected SerializedProperty defaultHorizontalAlignmentProp;
        protected SerializedProperty defaultVerticalAlignmentProp;

        private static readonly GUIContent k_defaultDeltaSizeLabel = new GUIContent("defaultDeltaSize");
        private static readonly GUIContent k_defaultFontLabel = new GUIContent("defaultFont");
        private static readonly GUIContent k_defaultFontSizeLabel = new GUIContent("defaultFontSize");
        private static readonly GUIContent k_defaultFontColorLabel = new GUIContent("defaultFontColor");
        private static readonly GUIContent k_AlignmentLabel = new GUIContent("defaultAlignment");

        protected virtual void OnEnable()
        {
            defaultDeltaSizeProp = serializedObject.FindProperty("defaultDeltaSize");
            defaultFontProp = serializedObject.FindProperty("defaultFont");
            defaultFontSizeProp = serializedObject.FindProperty("defaultFontSize");
            defaultFontColorProp = serializedObject.FindProperty("defaultFontColor");
            defaultHorizontalAlignmentProp = serializedObject.FindProperty("defaultHorizontalAlignment");
            defaultVerticalAlignmentProp = serializedObject.FindProperty("defaultVerticalAlignment");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.Space(10);

            EditorGUILayout.PropertyField(defaultDeltaSizeProp, k_defaultDeltaSizeLabel);

            EditorGUILayout.Space(10);

            EditorGUILayout.PropertyField(defaultFontProp, k_defaultFontLabel);

            EditorGUILayout.Space(10);

            EditorGUILayout.PropertyField(defaultFontSizeProp, k_defaultFontSizeLabel);

            EditorGUILayout.Space(10);

            EditorGUILayout.PropertyField(defaultFontColorProp, k_defaultFontColorLabel);

            EditorGUILayout.Space(10);

            DrawAlignment();

            EditorGUILayout.Space(10);

            serializedObject.ApplyModifiedProperties();
        }

        void DrawAlignment()
        {
            Rect rect = EditorGUILayout.GetControlRect(true, 20);
            EditorGUI.BeginProperty(rect, k_AlignmentLabel, defaultHorizontalAlignmentProp);
            EditorGUI.BeginProperty(rect, k_AlignmentLabel, defaultVerticalAlignmentProp);

            EditorGUI.PrefixLabel(rect, k_AlignmentLabel);
            rect.x += EditorGUIUtility.labelWidth;

            EditorGUI.PropertyField(rect, defaultHorizontalAlignmentProp, GUIContent.none);
            EditorGUI.PropertyField(rect, defaultVerticalAlignmentProp, GUIContent.none);

            EditorGUI.EndProperty();
            EditorGUI.EndProperty();
        }
    }
}
#endif

